from django.shortcuts import render
from django.http import HttpResponse
from django.db.models import Q
# Create your views here.
from django.contrib.auth.hashers import make_password, check_password
from .. import models
from django.core.urlresolvers import reverse
from web.settings import BASE_DIR
import os
from .viewsIndex import uploads
from .viewsIndex import pages
from django.contrib.auth.decorators import permission_required


@permission_required('myadmin.show_order',raise_exception = True)
#后台订单列表
def ordersindex(request):

    #获取所有用户数据
    orderslist = models.OrderInfo.objects.filter()
    
    
    context = {'orderslist':orderslist}
    return render(request,'myadmin/orders/index.html',context)
    




@permission_required('myadmin.edit_order',raise_exception = True)
#订单状态修改
def ordersedit(request,oid):
    try:
        #根据oid获取订单对象,修改状态
        ob = models.Order.objects.get(id=oid)
        ob.status = 2
        ob.save()
        return HttpResponse('<script>alert("修改成功");location.href="'+reverse('myadmin_orders_index')+'"</script>')
    except:
        return HttpResponse('<script>alert("修改失败");location.href="'+reverse('myadmin_orders_index')+'"</script>')


